<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>抢筹</title>
		<link href="css/text.css" rel="stylesheet" type="text/css" />
		<style type="text/css">				
			//p {margin:5px}
			//ul {margin:1px}			
			//h4 {margin:1px}	
			.fixedBox{
				border: 1px solid #555555;				
				white-space: nowrap;	
			}
			.fixedBox::-webkit-scrollbar {
				width: 10px;     
				height: 10px;				
			}
			table{
			width:480px; 
			border-collapse:collapse; 
			text-align:center;
			}
			td,th{border:1px solid #696969}	
		</style>
	</head>
	<body>
		<div id="towrite" class="fixedBox"></div>	
		<script type="text/javascript" src="js/json2html.js"></script>
		<script type="text/javascript" src="js/jquery.min.js"></script>
		<script>
			var bkcolor = $("body").css("backgroundColor")
			window.onload = function() {						
			getSource("0","1");
			changeStyle();
			}
						
			function time_range(beginTime, endTime) {
				var strb = beginTime.split(":");
				if (strb.length != 2) {
					return false;
				}

				var stre = endTime.split(":");
				if (stre.length != 2) {
					return false;
				}

				var b = new Date();
				var e = new Date();
				var n = new Date();

				b.setHours(strb[0]);
				b.setMinutes(strb[1]);
				e.setHours(stre[0]);
				e.setMinutes(stre[1]);

				if (n.getTime() - b.getTime() > 0 && n.getTime() - e.getTime() < 0) {
					getSource("0",px);					
					console.log(true)　　　　　　
					return true;				
				} else {
					console.log(false)
				    return false;     
				}
			}　　　
   　　　
			$(function() {
				setInterval(function() {
				time_range("9:00","10:00")									
				},
				60000);
			})
			
			function changeStyle() {
				var obj1 = document.getElementById("towrite");				
				obj1.style.left= "0px"; 				
				obj1.style.width= "480px";	
				//obj1.style.height= "620px";		
				obj1.style.fontSize="12px";				  			 
			}	
			
			Date.prototype.Format = function (fmt) {
				var o = {
				"M+": this.getMonth() + 1, //月份
				"d+": this.getDate(), //日
				"h+": this.getHours(), //小时
				"m+": this.getMinutes(), //分
				"s+": this.getSeconds(), //秒
				"q+": Math.floor((this.getMonth() + 3) / 3), //季度
				"S": this.getMilliseconds() //毫秒
				};
				if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
				for (var k in o)
				if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
				return fmt;
			};
			
			function getLocalTime(nS) {			          
			return new Date(parseInt(nS) * 1000).Format("hh:mm:ss")}						
			
			function keepTwoDecimal(num) {  
               var result = parseFloat(num);  
               if (isNaN(result)) {  
                   //alert('传递参数错误，请检查！');  
                   return false;  
               }  
               result = Math.round(num * 100) / 100;  
               return result;  
			};
			
			function NumberTransform(num) { 
				var result = num;
				if(Math.abs(num) > 100000000){
					result = num / 100000000;
					result = result.toFixed(2) + "亿";
				}else if(Math.abs(num) > 10000){
					result = num/10000;
					result = result.toFixed(0) + "万";
				}				   
				return result;  
			};	

			var trid = "";
			function changeCss(obj,hid,id){						
				var tlist = document.getElementById(id).getElementsByTagName("tr");					
				for(var i = 0; i < tlist.length; i++){														
					tlist[i].style.backgroundColor = bkcolor; 					
				}
				trid = hid;
				var tr = document.getElementById(hid);				
				tr.style.backgroundColor = "#483D8B";						
			}
			
			function hover(){  //鼠标经过
				var rows = document.getElementsByTagName('tr');
				for(var i=0;i<rows.length;i++){
					rows[i].onmouseover=function(){						
						if(this.id != ""){  //过滤表头
							this.style.background="#800000";
						}
					}
					rows[i].onmouseout=function(){
						if(this.id != ""){  //过滤表头
							if(this.id != trid){  //过滤选中行
								this.style.background=bkcolor;
							}else{
								this.style.background="#483D8B";
							}
						}						
					}					
				}
			}			
			
			var t = "";
			var px = "1";
			var gl = "抢筹委托金额";  //高亮
			var dms = "";
			function getSource(ss,pp) {
				t = ss;
				px = pp;
				var zp = "<a href='javascript:void(0)' id='bt1' onclick='getSource(" + "\"0\"" + "," + px + ")'>" + "早盘抢筹" + "</a>";
				var wp = "<a href='javascript:void(0)' id='bt2' onclick='getSource(" + "\"1\"" + "," + px + ")'>" + "尾盘抢筹" + "</a>";	
				
				div1 = document.getElementById('towrite');
				div1.innerHTML = "<h4 style='margin-top:-5px;'>" + zp + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + wp + "</h4>";
				
				if(t == "0"){
					aObj = document.getElementById('bt1');				
					aObj.style.color = "#FFA07A";
				}
				
				if(t == "1"){
					aObj = document.getElementById('bt2');				
					aObj.style.color = "#FFA07A"; 
				}
				
				var url = "http://excalc.icfqs.com:7616/TQLEX?Entry=HQServ.hq_nlp"; 	                			
				//createXmlHttp();
				//早盘				
				var array1 = '[{"funcId":20,"offset":0,"count":50,"sort":' + px + ',"period":0,"Token":"6679f5cadca97d68245a086793fc1bfc0a50b487487c812f","modname":"JJQC","date":20230330}]';
				array1 = eval(array1);
				
				//尾盘				
				var array2 = '[{"funcId":20,"offset":0,"count":50,"sort":' + px + ',"period":1,"Token":"6679f5cadca97d68245a086793fc1bfc0a50b487487c812f","modname":"JJQC","date":20230330}]';
				array2 = eval(array2);	
				
				var array = [];
				if(ss == "0"){	
					array = array1;						
				}
				if(ss == "1"){											
					array = array2;	
				}		
				
				var res = [];
				$.ajax({
					type: "post",
					url: url,
					data : JSON.stringify(array),					
					headers: {"User-Agent":"TdxW"},
					dataType: "json",
					async : false,
					cache:false,
					timeout:3000,					
					success: function(data) {
						//alert(JSON.stringify(data))						
						//document.write(JSON.stringify(data));							
						for (i = 0; i < data.datas.length; i++){
							var aa = data.datas[i];
							res.push({"code":aa[0],"name":aa[1],"kpje":NumberTransform(aa[4]),"fd":keepTwoDecimal(aa[5]*100),"wtje":NumberTransform(aa[6]),"cjje":NumberTransform(aa[7])});							
						}									
					}
				});	
				
				if(res.length > 0){	
				
					var json = res;
					//创建table					
					var table=document.createElement("table");										
					var thead=document.createElement("thead");
					table.appendChild(thead);					
					var tr=document.createElement("tr");
					thead.appendChild(tr);					
					
					var m = 0;
					var n = 0;
					var b = 0;
					for(var key in json[0]){  //表头
						key = key.replace('code','代码').replace('name','名称').replace('fd','抢筹幅度%').replace('wtje','抢筹委托金额').replace('cjje','抢筹成交金额');							
						var ks = "";
						if(t == "0"){
							key = key.replace('kpje','开盘金额');															
						}else{
							key = key.replace('kpje','收盘金额')															
						}									
						var th=document.createElement("th");						
						th.innerHTML=key;						
						tr.appendChild(th);
						if(gl == "开盘金额" && t == 1){
							gl = "收盘金额"
						}else if(gl == "收盘金额" && t == 0){
							gl = "开盘金额"
						}
						if(gl == key){
							n = m;
							th.style.color = "#FF6633";	
						}							
						m++;
					}
										
					var tbody=document.createElement("tbody");					
					table.appendChild(tbody);
					
					//遍历json
					for(var i = 0; i < json.length; i++){					
						var tr=document.createElement("tr");						
						var p = 1;
						var dm = "";
						var mc = "";
						for(var key in json[i]){ //行元素遍历						
							var td=document.createElement("td");							
							
							var rc = json[i][key];
							if(p == 1){  //代码列
								dm = rc;
								tr.id = dm;
							}else if(p == 2){  //名称列
								mc = rc;								
							}					
							td.innerHTML = "<a href=http://www.treeid/code_" + dm + " id='" + p + "' onclick='changeCss(this,\"" + dm + "\",\"gg\")'>" + rc + "</a>";
						
							if(p == n + 1){							
								//td.style.color = "#FF6633";	
								td.getElementsByTagName("a")[0].style.color = "#FF6633";									
							}								
							tr.appendChild(td);
							p++;
						}						
						if(mc.indexOf("ST") == -1 && dm.substr(0,3) != "688"){		//过滤ST、科创板										
							tbody.appendChild(tr);
						}	
					}					
					var div = document.getElementById("towrite");									
					div.appendChild(table);
					table.id = "gg";
					table.style.marginTop = "5px";
					hover();
					makeSortable(table);
				}else{						
					div1.innerHTML += "暂无数据";
				}									
			}
			
			function makeSortable(table) {
				var headers=table.getElementsByTagName("th");
				for(var i = 0; i < headers.length; i++){				
					(function(n){											
						headers[n].onclick = function(){							
							if(n > 1){
								gl = headers[n].textContent;
								var p = 0;
								if(n == 2){  //开盘金额	
									p = 3;
								}else if(n == 3){  //抢筹幅度
									p = 4;
								}else if(n == 4){  //抢筹委托金额
									p = 1;
								}else if(n == 5){  //抢筹成交金额
									p = 2;
								}
								getSource(t , p);
							}
						}
					}(i));
				}
			}
		</script>	
	</body>
</html>